package com.bzkj.basicinfo.service.impl.ncc;

import com.bzkj.basicinfo.domain.ncc.BasicStoShelf;
import com.bzkj.basicinfo.mapper.BasicStoShelfMapper;
import com.bzkj.basicinfo.service.ncc.BasicStoShelfService;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.core.domain.entity.SysUser;
import com.bzkj.common.core.domain.model.LoginUser;
import com.bzkj.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class BasicStoShelfServiceImpl implements BasicStoShelfService {
    @Autowired
    private BasicStoShelfMapper basicStoShelfMapper;

    @Override
    public AjaxResult addBasicStoShelf(BasicStoShelf basicStoShelf) {
        BasicStoShelf basicStoShelfByTag = basicStoShelfMapper.getBasicStoShelfByTag(basicStoShelf.getTag());
        if (basicStoShelfByTag!=null){
            return AjaxResult.error("已存在当前编码的货位");
        }else{
//            没获取到，新增
            LoginUser loginUser = SecurityUtils.getLoginUser();
            SysUser user = loginUser.getUser();
            String userName = user.getUserName();
            String s = getFour();
            basicStoShelf.setCode(s);
            basicStoShelf.setCreator(userName);
            basicStoShelf.setCreateTime(new Date());
            basicStoShelf.setDef1("1");
            basicStoShelfMapper.insert(basicStoShelf);
            return AjaxResult.success();
        }
    }

    @Override
    public int updateBasicStoShelf(BasicStoShelf basicStoShelf) {
        return basicStoShelfMapper.updateBasicStoShelf(basicStoShelf);
    }

    @Override
    public int deleteBasicStoShelf(Integer id) {
        return basicStoShelfMapper.deleteBasicStoShelf(id);
    }

    @Override
    public BasicStoShelf getBasicStoShelf(Integer id) {
        return basicStoShelfMapper.getBasicStoShelf(id);
    }

    @Override
    public List<BasicStoShelf> getAllBasicStoShelf(BasicStoShelf basicStoShelf) {
        return basicStoShelfMapper.selectAllBasicStoShelf();
    }

    @Override
    public List<BasicStoShelf> getAllBasicStoUnit(BasicStoShelf basicStoShelf) {
        return basicStoShelfMapper.selectAllBasicStoUnit();
    }

    public  String getFour() {
        Long aLong = basicStoShelfMapper.queryBigNumber();
        if (aLong==null){
            return "400000000";
        }else{
            aLong = aLong + 1;
            return aLong+"";
        }
    }
}
